package com.lyc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyc.dao.UserDao;
import com.lyc.entity.User;
import com.lyc.service.UserService;
import com.lyc.vo.LoginVo;
import com.lyc.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/18 19:46
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;


    @Override
    public Result findAll(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> all = userDao.findAll();
        PageInfo<User> pageInfo = new PageInfo<>(all);
        System.out.println("总条数"+pageInfo.getTotal());
        System.out.println("当前页码的条数"+pageInfo.getList());
        return new Result(2000,"查询成功",pageInfo);

    }

    @Override
    public Result select(User user) {
        List<User> users = userDao.select(user);
        return new Result(2000,"查询成功",users);
    }

    @Override
    public int insert(User user) {
        int insert = userDao.insert(user);
        return insert;
    }

    @Override
    public int updateById(User user) {
        int i = userDao.updateById(user);
        return i;
    }

    @Override
    public int deleteById(int id) {
        int i = userDao.deleteById(id);
        return i;
    }

}